﻿using AdverseEventReportSystem.BLL.EscortManageSys;
using AdverseEventReportSystem.Core;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AdverseEventReportSystem.Web.Areas.Escort.Controllers
{
    public class DateTempListController : BaseController
    {
        EscortManageSysSoapClient service = new EscortManageSysSoapClient();
        //
        // GET: /Escort/DateTempList/
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Search()
        {
            string cellcode = Request["nurseCellCode"];
            string date = Request["date"];
            if (string.IsNullOrEmpty(cellcode)) return JsonDate(new { Total = 0, Rows = new DataTable() });
            if (string.IsNullOrEmpty(date)) return JsonDate(new { Total = 0, Rows = new DataTable() });
            var ret = service.GetEscortListByNursingWard(cellcode, Convert.ToDateTime(date));
            if (ret.S)
            {
                var jsonobj = JsonConvert.DeserializeObject<dynamic>(ret.D);
                var result = new { Total = jsonobj.Total, Rows = jsonobj.Rows };
                return JsonDate(result);
            }
            return JsonDate(new { Total = 0, Rows = new DataTable() });
        }
        public ActionResult Save()
        {
            string loginUserId = loginUser.Id.ToString();
            string datajson = Request["datajson"];
            string date = Request["date"];
            string stime = Request["stime"];
            string etime = Request["etime"];
            if (string.IsNullOrEmpty(datajson))
            {
                return JsonDate(new OperateResult(0, "暂无数据可以保存"));
            }
            if (string.IsNullOrEmpty(date))
            {
                return JsonDate(new OperateResult(0, "日期不能为空"));
            }
            if (string.IsNullOrEmpty(stime))
            {
                return JsonDate(new OperateResult(0, "起始时间不能为空"));
            }
            if (string.IsNullOrEmpty(etime))
            {
                return JsonDate(new OperateResult(0, "结束时间不能为空"));
            }
            var ret = service.SaveEscortTemprature(loginUserId, datajson, Convert.ToDateTime(date), stime, etime);
            if (ret.S)
            {
                return JsonDate(new OperateResult(1, ret.M));
            }
            else
            {
                return JsonDate(new OperateResult(0, ret.M));
            }
        }
    }
}